home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 4 #9 / IMG 40 Sep 1996.iso / More Goodies / More for Your Game / Sprite Fight 2002 / SpriteTool#3 Folder / SpriteFlipNMask.c < prev   
C/C++ Source or Header  |  1996-07-18  |  21KB  |  754 lines

  1. //• SpriteFlipNMask.c
  2. //• Copyright (c) 1996 by Stefan C. Sinclair
  3. //• All Rights Reserved Worldwide
  4. //• Flips the PICTs & then creates the Mask PICTs
  5.  
  6. #include <EPPC.h>
  7. #include <GestaltEqu.h>
  8. #include <AppleEvents.h>
  9. #include <Movies.h>
  10. #include <ctype.h>
  11. #include <Sound.h>
  12. #include <Dialogs.h>
  13.  
  14. #define kGestaltMask        1L
  15.  
  16. #define    kErrorAlertID                    128
  17. #define kMinTextPosition    0
  18. #define kMaxTextPosition    32767
  19.  
  20. #define kFirstLifePICT            128
  21. #define kNumLifePICT            43
  22. #define kFirstProjectilePICT    214
  23. #define kNumProjectilePICT        2
  24. #define kFirstDeathPICT            218
  25. #define kNumDeathPICT            10
  26. #define kRideChairPICT            238
  27. #define kSitChairPICT            240
  28. #define kMaskOffset                200
  29.  
  30. void InitToolbox(void);
  31. void AEInstallHandlers(void);
  32. pascal OSErr DoOpenApp( AppleEvent *event, AppleEvent *reply, long refcon);
  33. pascal OSErr DoOpenDoc( AppleEvent *event, AppleEvent *reply, long refcon);
  34. pascal OSErr DoPrintDoc( AppleEvent *event, AppleEvent *reply, long refcon);
  35. pascal OSErr DoQuitApp( AppleEvent *event, AppleEvent *reply, long refcon);
  36. OSErr CheckForRequiredParams( AppleEvent *event);
  37. void AEInit(void);
  38. void  MoviesInit( void );
  39. void  Open_A_Movie( void );
  40. void  Close_A_Movie( void );
  41. void DoError (char desc[255], short OScode, short myRef, Boolean fatal);
  42. void pStrCopy (StringPtr p1, StringPtr p2);
  43. pascal Boolean SpriteGuyFileFilter(fileParam *thePB );
  44. void  Handle_One_Event( void );
  45.  
  46. Boolean    All_Done = FALSE;
  47. EventRecord      The_Event;
  48.  
  49. main()
  50. {
  51.     InitToolbox();
  52.     MoviesInit();
  53.     AEInit();
  54.     
  55.     while ( All_Done == false )
  56.       Handle_One_Event();
  57.       
  58.     DoError("Ha! No errors! Apparently, it worked.", 0, 0, FALSE);
  59.  
  60.     return 0;
  61. }
  62.  
  63. void  Handle_One_Event( void )
  64. {        
  65.    WindowPtr  which_window;
  66.    long       movie_related_event;
  67.       
  68.    WaitNextEvent(everyEvent, &The_Event, 0, nil);
  69.     switch (The_Event.what)
  70.      {
  71.          case keyDown:
  72.          case autoKey:
  73.             break;
  74.          case updateEvt:
  75.             break;
  76.          case mouseDown:
  77.              Open_A_Movie();  
  78.             break;
  79.          case kHighLevelEvent:
  80.             AEProcessAppleEvent(&The_Event);
  81.             break;
  82.    }
  83. }
  84.  
  85. void InitToolbox()
  86. {
  87.     InitGraf((Ptr) &qd.thePort);
  88.     InitFonts();
  89.     InitWindows();
  90.     InitMenus();
  91.     FlushEvents(everyEvent,0);
  92.     TEInit();
  93.     InitDialogs(0L);
  94.     InitCursor();
  95. }
  96.  
  97. void  MoviesInit( void )
  98. {
  99.    OSErr  error;
  100.    long   result;
  101.     
  102.    error = Gestalt( gestaltQuickTime, &result );
  103.    if ( error != noErr )
  104.       DoError("Sorry, but you need QuickTime™ installed for this program to work.",0,0,TRUE);
  105.                                              
  106.    error = EnterMovies();  
  107.    if ( error != noErr )
  108.       DoError("Sorry, but you need QuickTime™ installed for this program to work.",0,0,TRUE); 
  109. }
  110.  
  111. void AEInit( void)
  112. {
  113.     OSErr    err;
  114.     long    feature;
  115.     
  116.     err = Gestalt(gestaltAppleEventsAttr, &feature);
  117.     if(err != noErr)
  118.         DoError("Error returned by gestalt!",0,0, true);
  119.     if(!(feature & (kGestaltMask << gestaltAppleEventsPresent)))
  120.         DoError("Apple Events not supported!",0,0, true);
  121.     AEInstallHandlers();
  122. }
  123.  
  124. void AEInstallHandlers(void)
  125. {
  126.     OSErr    err;
  127.     /* install the required apple event handlers */
  128.     AEEventHandlerUPP OPENae, QUITae, STARTae, PRINTae;
  129.     
  130.     /* must use these for PPC proc pointers */
  131.     OPENae = NewAEEventHandlerProc ((ProcPtr) &DoOpenDoc);
  132.     QUITae = NewAEEventHandlerProc ((ProcPtr) &DoQuitApp);
  133.     STARTae = NewAEEventHandlerProc ((ProcPtr) &DoOpenApp);
  134.     PRINTae = NewAEEventHandlerProc ((ProcPtr) &DoPrintDoc);
  135.     err = AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,STARTae, 0L, false);
  136.     if(err != noErr)
  137.         DoError("Error installing 'open app' handler!",0,0, true);
  138.     err = err = AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments, OPENae, 0L, false);
  139.     if(err != noErr)
  140.         DoError("Error installing 'open doc' handler!",0,0, true);
  141.     err = err = AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments, PRINTae, 0L, false);
  142.     if(err != noErr)
  143.         DoError("Error installing 'print doc' handler!",0,0, true);
  144.     err = err = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, QUITae, 0L, false);
  145.     if(err != noErr)
  146.         DoError("Error installing 'quit app' handler!",0,0, true);
  147. }
  148.  
  149. pascal OSErr DoOpenApp( AppleEvent *event, AppleEvent *reply, long refcon)
  150. {
  151.     Open_A_Movie();
  152.     return noErr;
  153. }
  154.  
  155. pascal OSErr DoOpenDoc( AppleEvent *event, AppleEvent *reply, long refcon)
  156. {
  157.     OSErr        err;
  158.     FSSpec        fileSpec;
  159.     long        i, numDocs;
  160.     DescType    returnedType;
  161.     AEKeyword    keywd;
  162.     Size        actualSize;
  163.     AEDescList    docList = {typeNull, nil};    // Get the direct parameter-a descriptor list-and put into docList
  164.     
  165.     err = AEGetParamDesc(event, keyDirectObject, typeAEList, &docList);
  166.     err = CheckForRequiredParams( event);    // Check for missing required parameters
  167.     if(err)
  168.     {
  169.         err = AEDisposeDesc( &docList);
  170.         return err;
  171.     }
  172.     err = AECountItems( &docList, &numDocs);    // Count #of descriptor records in the list
  173.     if(err)                                    // Should be at least 1 since we got called & no error.
  174.     {
  175.         err = AEDisposeDesc( &docList);
  176.         return err;
  177.     }
  178.     // Now get each descriptor record, coerce data to an FSSpec record, & open the file
  179.     //for( i = 1; i <= numDocs; i++)
  180.     //{
  181.         err = AEGetNthPtr( &docList, 1, typeFSS, &keywd, &returnedType, (Ptr)&fileSpec, sizeof(fileSpec), &actualSize);
  182.         Open_A_Movie();
  183.     //}
  184.     err = AEDisposeDesc( &docList);
  185.     return err;
  186. }
  187.  
  188.  
  189. OSErr CheckForRequiredParams( AppleEvent *appleEventPtr)
  190. {
  191.     DescType        returnedType;
  192.     Size            actualSize;
  193.     OSErr            err;
  194.     
  195.     err = AEGetAttributePtr( appleEventPtr, keyMissedKeywordAttr, typeWildCard, &returnedType, nil, 0, &actualSize);
  196.     //• Looks for specified attribute, returns attribute status as an error
  197.     
  198.     if( err == errAEDescNotFound)
  199.         return noErr;
  200.     else if( err == noErr)
  201.         return errAEParamMissed;
  202.     else
  203.         return err;
  204. }
  205.  
  206. pascal OSErr DoPrintDoc( AppleEvent *event, AppleEvent *reply, long refcon)
  207. {
  208.     return noErr;
  209. }
  210.  
  211. pascal OSErr DoQuitApp( AppleEvent *event, AppleEvent *reply, long refcon)
  212. {
  213.     All_Done = true;
  214.     return noErr;
  215. }
  216.  
  217. void  Open_A_Movie( void )
  218. {  
  219.    SFTypeList         type_list = { MovieFileType,'MYqt', 0, 0 };
  220.    StandardFileReply  the_reply;
  221.    Str255             movie_name;
  222.    Boolean            was_changed;
  223.    FileFilterUPP      myFileFilter;
  224.    short            curResRefNum, i, j, k, x, y, high, wide;
  225.    Rect                rWind, rPICT, rPICT2;
  226.    CWindowPtr        aWindow;
  227.    OSErr            err;
  228.    BitMap            bmp;
  229.    PicHandle        spritePICT, flipPICT, maskPICT, flipMaskPICT;
  230.    Rect    r;
  231.     RGBColor    c, b = {0,0,0}, w = {65535, 65535, 65535};
  232.    
  233.        myFileFilter = NewFileFilterProc(SpriteGuyFileFilter);
  234.       StandardGetFilePreview( myFileFilter, -1/*numTypes*/, type_list, &the_reply );
  235.        if( the_reply.sfGood != true )
  236.            ExitToShell();
  237.        else
  238.       {          
  239.            curResRefNum = HOpenResFile(the_reply.sfFile.vRefNum,
  240.                 the_reply.sfFile.parID,the_reply.sfFile.name,
  241.                 fsRdWrPerm);
  242.         err = ((ResError()!=noErr) || (curResRefNum < 0));
  243.         
  244.         if (err != noErr)
  245.             DoError("Error opening resource fork!",err,0,TRUE);
  246.         else
  247.         {    
  248.             rWind.top = rWind.left = 60;
  249.             rWind.bottom = 300;
  250.             rWind.right = 600;
  251.             
  252.             aWindow = (CWindowPtr)NewCWindow(nil, &rWind, "\pFlip 'n Mask",
  253.                     TRUE, documentProc, (WindowPtr)-1L, TRUE, 0);
  254.             SetPort((GrafPtr)aWindow);
  255.             ShowWindow((WindowPtr)aWindow);
  256.             ValidRect(&aWindow->portRect);
  257.             
  258.             UseResFile(curResRefNum);
  259.             
  260.             ForeColor(blackColor);
  261.             BackColor(whiteColor);
  262.  
  263.             for(i=kFirstLifePICT; i<(kFirstLifePICT+kNumLifePICT); i++)
  264.             {
  265.                   ClipRect(&qd.thePort->portRect);
  266.                   EraseRect(&qd.thePort->portRect);
  267.                 spritePICT = (PicHandle)Get1Resource('PICT', i);
  268.                 if(spritePICT == NULL)
  269.                     DoError("File is missing a PICT resource!",i,0,TRUE);
  270.                 HLock((Handle)spritePICT);
  271.                 rPICT = (**spritePICT).picFrame;
  272.                 rPICT2 = rPICT;
  273.                 high = rPICT.bottom - rPICT.top;
  274.                 wide = rPICT.right - rPICT.left;
  275.                 DrawPicture(spritePICT, &rPICT);
  276.                 rPICT2.left+=(wide+1);
  277.                 rPICT2.right+=(wide+1);
  278.                 // flip it
  279.                 for(j=0; j<wide; j++)
  280.                 {
  281.                     for(k=0; k<high; k++)
  282.                     {
  283.                         GetCPixel(j, k, &c);
  284.                         x = rPICT2.right - j;
  285.                         SetCPixel(x, k, &c);
  286.                             
  287.                     }
  288.                 }
  289.                 flipPICT = OpenPicture(&rPICT2);
  290.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  291.                     &rPICT2, &rPICT2, srcCopy, nil);
  292.                 ClosePicture();
  293.                 AddResource((Handle)flipPICT, 'PICT', (i+kNumLifePICT), "\p");
  294.                 if(ResError())
  295.                 {
  296.                     DoError("ResError!",i,ResError(),TRUE);
  297.                 }
  298.                 WriteResource((Handle)flipPICT);
  299.                 
  300.                 // mask the original
  301.                 for(j=0; j<wide; j++)
  302.                 {
  303.                     for(k=0; k<high; k++)
  304.                     {
  305.                         GetCPixel(j, k, &c);
  306.                         if(c.red == w.red && c.blue == w.blue && c.green == w.green)
  307.                             ;
  308.                         else
  309.                             SetCPixel(j, k, &b); // not white, so make it black
  310.                     }
  311.                 }
  312.                 maskPICT = OpenPicture(&rPICT);
  313.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  314.                     &rPICT, &rPICT, srcCopy, nil);
  315.                 ClosePicture();
  316.                 AddResource((Handle)maskPICT, 'PICT', (i+kMaskOffset), "\p");
  317.                 if(ResError())
  318.                 {
  319.                     DoError("ResError!",i,ResError(),TRUE);
  320.                 }
  321.                 WriteResource((Handle)maskPICT);
  322.                 
  323.                 // flip the mask now
  324.                 for(j=0; j<wide; j++)
  325.                 {
  326.                     for(k=0; k<high; k++)
  327.                     {
  328.                         GetCPixel(j, k, &c);
  329.                         x = rPICT2.right - j;
  330.                         SetCPixel(x, k, &c);
  331.                             
  332.                     }
  333.                 }
  334.                 flipMaskPICT = OpenPicture(&rPICT2);
  335.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  336.                     &rPICT2, &rPICT2, srcCopy, nil);
  337.                 ClosePicture();
  338.                 AddResource((Handle)flipMaskPICT, 'PICT', (i+kNumLifePICT+kMaskOffset), "\p");
  339.                 if(ResError())
  340.                 {
  341.                     DoError("ResError!",i,ResError(),TRUE);
  342.                 }
  343.                 WriteResource((Handle)flipMaskPICT);
  344.                 
  345.                 // dispose of all PICTs
  346.                 ReleaseResource((Handle)spritePICT);
  347.                 ReleaseResource((Handle)maskPICT);
  348.                 ReleaseResource((Handle)flipMaskPICT);
  349.                 ReleaseResource((Handle)flipPICT);
  350.                 
  351.                 EraseRect(&qd.thePort->portRect);
  352.             }
  353.             
  354.             for(i=kFirstProjectilePICT; i<(kFirstProjectilePICT+kNumProjectilePICT); i++)
  355.             {
  356.                   ClipRect(&qd.thePort->portRect);
  357.                   EraseRect(&qd.thePort->portRect);
  358.                 spritePICT = (PicHandle)Get1Resource('PICT', i);
  359.                 if(spritePICT == NULL)
  360.                     DoError("File is missing a PICT resource!",i,0,TRUE);
  361.                 HLock((Handle)spritePICT);
  362.                 rPICT = (**spritePICT).picFrame;
  363.                 rPICT2 = rPICT;
  364.                 high = rPICT.bottom - rPICT.top;
  365.                 wide = rPICT.right - rPICT.left;
  366.                 DrawPicture(spritePICT, &rPICT);
  367.                 rPICT2.left+=(wide+1);
  368.                 rPICT2.right+=(wide+1);
  369.                 DrawPicture(spritePICT, &rPICT);
  370.                 // flip it
  371.                 for(j=0; j<wide; j++)
  372.                 {
  373.                     for(k=0; k<high; k++)
  374.                     {
  375.                         GetCPixel(j, k, &c);
  376.                         x = rPICT2.right - j;
  377.                         SetCPixel(x, k, &c);
  378.                             
  379.                     }
  380.                 }
  381.                 flipPICT = OpenPicture(&rPICT2);
  382.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  383.                     &rPICT2, &rPICT2, srcCopy, nil);
  384.                 ClosePicture();
  385.                 AddResource((Handle)flipPICT, 'PICT', (i+kNumProjectilePICT), "\p");
  386.                 if(ResError())
  387.                 {
  388.                     DoError("ResError!",i,ResError(),TRUE);
  389.                 }
  390.                 WriteResource((Handle)flipPICT);
  391.                 
  392.                 // mask the original
  393.                 for(j=0; j<wide; j++)
  394.                 {
  395.                     for(k=0; k<high; k++)
  396.                     {
  397.                         GetCPixel(j, k, &c);
  398.                         if(c.red == w.red && c.blue == w.blue && c.green == w.green)
  399.                             ;
  400.                         else
  401.                             SetCPixel(j, k, &b); // not white, so make it black
  402.                     }
  403.                 }
  404.                 maskPICT = OpenPicture(&rPICT);
  405.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  406.                     &rPICT, &rPICT, srcCopy, nil);
  407.                 ClosePicture();
  408.                 AddResource((Handle)maskPICT, 'PICT', (i+kMaskOffset), "\p");
  409.                 if(ResError())
  410.                 {
  411.                     DoError("ResError!",i,ResError(),TRUE);
  412.                 }
  413.                 WriteResource((Handle)maskPICT);
  414.                 
  415.                 // flip the mask now
  416.                 for(j=0; j<wide; j++)
  417.                 {
  418.                     for(k=0; k<high; k++)
  419.                     {
  420.                         GetCPixel(j, k, &c);
  421.                         x = rPICT2.right - j;
  422.                         SetCPixel(x, k, &c);
  423.                             
  424.                     }
  425.                 }
  426.                 flipMaskPICT = OpenPicture(&rPICT2);
  427.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  428.                     &rPICT2, &rPICT2, srcCopy, nil);
  429.                 ClosePicture();
  430.                 AddResource((Handle)flipMaskPICT, 'PICT', (i+kNumProjectilePICT+kMaskOffset), "\p");
  431.                 if(ResError())
  432.                 {
  433.                     DoError("ResError!",i,ResError(),TRUE);
  434.                 }
  435.                 WriteResource((Handle)flipMaskPICT);
  436.                 
  437.                 // dispose of all PICTs
  438.                 ReleaseResource((Handle)spritePICT);
  439.                 ReleaseResource((Handle)maskPICT);
  440.                 ReleaseResource((Handle)flipMaskPICT);
  441.                 ReleaseResource((Handle)flipPICT);
  442.                 
  443.                 EraseRect(&qd.thePort->portRect);
  444.             }
  445.  
  446.             for(i=kFirstDeathPICT; i<(kFirstDeathPICT+kNumDeathPICT); i++)
  447.             {
  448.                   ClipRect(&qd.thePort->portRect);
  449.                   EraseRect(&qd.thePort->portRect);
  450.                 spritePICT = (PicHandle)Get1Resource('PICT', i);
  451.                 if(spritePICT == NULL)
  452.                     DoError("File is missing a PICT resource!",i,0,TRUE);
  453.                 HLock((Handle)spritePICT);
  454.                 rPICT = (**spritePICT).picFrame;
  455.                 rPICT2 = rPICT;
  456.                 high = rPICT.bottom - rPICT.top;
  457.                 wide = rPICT.right - rPICT.left;
  458.                 DrawPicture(spritePICT, &rPICT);
  459.                 rPICT2.left+=(wide+1);
  460.                 rPICT2.right+=(wide+1);
  461.                 DrawPicture(spritePICT, &rPICT);
  462.                 // flip it
  463.                 for(j=0; j<wide; j++)
  464.                 {
  465.                     for(k=0; k<high; k++)
  466.                     {
  467.                         GetCPixel(j, k, &c);
  468.                         x = rPICT2.right - j;
  469.                         SetCPixel(x, k, &c);
  470.                             
  471.                     }
  472.                 }
  473.                 flipPICT = OpenPicture(&rPICT2);
  474.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  475.                     &rPICT2, &rPICT2, srcCopy, nil);
  476.                 ClosePicture();
  477.                 AddResource((Handle)flipPICT, 'PICT', (i+kNumDeathPICT), "\p");
  478.                 if(ResError())
  479.                 {
  480.                     DoError("ResError!",i,ResError(),TRUE);
  481.                 }
  482.                 WriteResource((Handle)flipPICT);
  483.                 
  484.                 // mask the original
  485.                 for(j=0; j<wide; j++)
  486.                 {
  487.                     for(k=0; k<high; k++)
  488.                     {
  489.                         GetCPixel(j, k, &c);
  490.                         if(c.red == w.red && c.blue == w.blue && c.green == w.green)
  491.                             ;
  492.                         else
  493.                             SetCPixel(j, k, &b); // not white, so make it black
  494.                     }
  495.                 }
  496.                 maskPICT = OpenPicture(&rPICT);
  497.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  498.                     &rPICT, &rPICT, srcCopy, nil);
  499.                 ClosePicture();
  500.                 AddResource((Handle)maskPICT, 'PICT', (i+kMaskOffset), "\p");
  501.                 if(ResError())
  502.                 {
  503.                     DoError("ResError!",i,ResError(),TRUE);
  504.                 }
  505.                 WriteResource((Handle)maskPICT);
  506.                 
  507.                 // flip the mask now
  508.                 for(j=0; j<wide; j++)
  509.                 {
  510.                     for(k=0; k<high; k++)
  511.                     {
  512.                         GetCPixel(j, k, &c);
  513.                         x = rPICT2.right - j;
  514.                         SetCPixel(x, k, &c);
  515.                             
  516.                     }
  517.                 }
  518.                 flipMaskPICT = OpenPicture(&rPICT2);
  519.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  520.                     &rPICT2, &rPICT2, srcCopy, nil);
  521.                 ClosePicture();
  522.                 AddResource((Handle)flipMaskPICT, 'PICT', (i+kNumDeathPICT+kMaskOffset), "\p");
  523.                 if(ResError())
  524.                 {
  525.                     DoError("ResError!",i,ResError(),TRUE);
  526.                 }
  527.                 WriteResource((Handle)flipMaskPICT);
  528.                 
  529.                 // dispose of all PICTs
  530.                 ReleaseResource((Handle)spritePICT);
  531.                 ReleaseResource((Handle)maskPICT);
  532.                 ReleaseResource((Handle)flipMaskPICT);
  533.                 ReleaseResource((Handle)flipPICT);
  534.                 
  535.                 EraseRect(&qd.thePort->portRect);
  536.             }
  537.             
  538.             for(i=kRideChairPICT; i<(kRideChairPICT+1); i++)
  539.             {
  540.                   ClipRect(&qd.thePort->portRect);
  541.                   EraseRect(&qd.thePort->portRect);
  542.                 spritePICT = (PicHandle)Get1Resource('PICT', i);
  543.                 if(spritePICT == NULL)
  544.                     DoError("File is missing a PICT resource!",i,0,TRUE);
  545.                 HLock((Handle)spritePICT);
  546.                 rPICT = (**spritePICT).picFrame;
  547.                 rPICT2 = rPICT;
  548.                 high = rPICT.bottom - rPICT.top;
  549.                 wide = rPICT.right - rPICT.left;
  550.                 DrawPicture(spritePICT, &rPICT);
  551.                 rPICT2.left+=(wide+1);
  552.                 rPICT2.right+=(wide+1);
  553.                 DrawPicture(spritePICT, &rPICT);
  554.                 // flip it
  555.                 for(j=0; j<wide; j++)
  556.                 {
  557.                     for(k=0; k<high; k++)
  558.                     {
  559.                         GetCPixel(j, k, &c);
  560.                         x = rPICT2.right - j;
  561.                         SetCPixel(x, k, &c);
  562.                             
  563.                     }
  564.                 }
  565.                 flipPICT = OpenPicture(&rPICT2);
  566.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  567.                     &rPICT2, &rPICT2, srcCopy, nil);
  568.                 ClosePicture();
  569.                 AddResource((Handle)flipPICT, 'PICT', (i+1), "\p");
  570.                 if(ResError())
  571.                 {
  572.                     DoError("ResError!",i,ResError(),TRUE);
  573.                 }
  574.                 WriteResource((Handle)flipPICT);
  575.                 
  576.                 // mask the original
  577.                 for(j=0; j<wide; j++)
  578.                 {
  579.                     for(k=0; k<high; k++)
  580.                     {
  581.                         GetCPixel(j, k, &c);
  582.                         if(c.red == w.red && c.blue == w.blue && c.green == w.green)
  583.                             ;
  584.                         else
  585.                             SetCPixel(j, k, &b); // not white, so make it black
  586.                     }
  587.                 }
  588.                 maskPICT = OpenPicture(&rPICT);
  589.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  590.                     &rPICT, &rPICT, srcCopy, nil);
  591.                 ClosePicture();
  592.                 AddResource((Handle)maskPICT, 'PICT', (i+kMaskOffset), "\p");
  593.                 if(ResError())
  594.                 {
  595.                     DoError("ResError!",i,ResError(),TRUE);
  596.                 }
  597.                 WriteResource((Handle)maskPICT);
  598.                 
  599.                 // flip the mask now
  600.                 for(j=0; j<wide; j++)
  601.                 {
  602.                     for(k=0; k<high; k++)
  603.                     {
  604.                         GetCPixel(j, k, &c);
  605.                         x = rPICT2.right - j;
  606.                         SetCPixel(x, k, &c);
  607.                             
  608.                     }
  609.                 }
  610.                 flipMaskPICT = OpenPicture(&rPICT2);
  611.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  612.                     &rPICT2, &rPICT2, srcCopy, nil);
  613.                 ClosePicture();
  614.                 AddResource((Handle)flipMaskPICT, 'PICT', (i+1+kMaskOffset), "\p");
  615.                 if(ResError())
  616.                 {
  617.                     DoError("ResError!",i,ResError(),TRUE);
  618.                 }
  619.                 WriteResource((Handle)flipMaskPICT);
  620.                 
  621.                 // dispose of all PICTs
  622.                 ReleaseResource((Handle)spritePICT);
  623.                 ReleaseResource((Handle)maskPICT);
  624.                 ReleaseResource((Handle)flipMaskPICT);
  625.                 ReleaseResource((Handle)flipPICT);
  626.                 
  627.                 EraseRect(&qd.thePort->portRect);
  628.             }
  629.             
  630.             for(i=kSitChairPICT; i<(kSitChairPICT+1); i++)
  631.             {
  632.                   ClipRect(&qd.thePort->portRect);
  633.                   EraseRect(&qd.thePort->portRect);
  634.                 spritePICT = (PicHandle)Get1Resource('PICT', i);
  635.                 if(spritePICT == NULL)
  636.                     DoError("File is missing a PICT resource!",i,0,TRUE);
  637.                 HLock((Handle)spritePICT);
  638.                 rPICT = (**spritePICT).picFrame;
  639.                 rPICT2 = rPICT;
  640.                 high = rPICT.bottom - rPICT.top;
  641.                 wide = rPICT.right - rPICT.left;
  642.                 DrawPicture(spritePICT, &rPICT);
  643.                 rPICT2.left+=(wide+1);
  644.                 rPICT2.right+=(wide+1);
  645.                 DrawPicture(spritePICT, &rPICT);
  646.                 // flip it
  647.                 for(j=0; j<wide; j++)
  648.                 {
  649.                     for(k=0; k<high; k++)
  650.                     {
  651.                         GetCPixel(j, k, &c);
  652.                         x = rPICT2.right - j;
  653.                         SetCPixel(x, k, &c);
  654.                             
  655.                     }
  656.                 }
  657.                 flipPICT = OpenPicture(&rPICT2);
  658.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  659.                     &rPICT2, &rPICT2, srcCopy, nil);
  660.                 ClosePicture();
  661.                 AddResource((Handle)flipPICT, 'PICT', (i+1), "\p");
  662.                 if(ResError())
  663.                 {
  664.                     DoError("ResError!",i,ResError(),TRUE);
  665.                 }
  666.                 WriteResource((Handle)flipPICT);
  667.                 
  668.                 // mask the original
  669.                 for(j=0; j<wide; j++)
  670.                 {
  671.                     for(k=0; k<high; k++)
  672.                     {
  673.                         GetCPixel(j, k, &c);
  674.                         if(c.red == w.red && c.blue == w.blue && c.green == w.green)
  675.                             ;
  676.                         else
  677.                             SetCPixel(j, k, &b); // not white, so make it black
  678.                     }
  679.                 }
  680.                 maskPICT = OpenPicture(&rPICT);
  681.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  682.                     &rPICT, &rPICT, srcCopy, nil);
  683.                 ClosePicture();
  684.                 AddResource((Handle)maskPICT, 'PICT', (i+kMaskOffset), "\p");
  685.                 if(ResError())
  686.                 {
  687.                     DoError("ResError!",i,ResError(),TRUE);
  688.                 }
  689.                 WriteResource((Handle)maskPICT);
  690.                 
  691.                 // flip the mask now
  692.                 for(j=0; j<wide; j++)
  693.                 {
  694.                     for(k=0; k<high; k++)
  695.                     {
  696.                         GetCPixel(j, k, &c);
  697.                         x = rPICT2.right - j;
  698.                         SetCPixel(x, k, &c);
  699.                             
  700.                     }
  701.                 }
  702.                 flipMaskPICT = OpenPicture(&rPICT2);
  703.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  704.                     &rPICT2, &rPICT2, srcCopy, nil);
  705.                 ClosePicture();
  706.                 AddResource((Handle)flipMaskPICT, 'PICT', (i+1+kMaskOffset), "\p");
  707.                 if(ResError())
  708.                 {
  709.                     DoError("ResError!",i,ResError(),TRUE);
  710.                 }
  711.                 WriteResource((Handle)flipMaskPICT);
  712.                 
  713.                 // dispose of all PICTs
  714.                 ReleaseResource((Handle)spritePICT);
  715.                 ReleaseResource((Handle)maskPICT);
  716.                 ReleaseResource((Handle)flipMaskPICT);
  717.                 ReleaseResource((Handle)flipPICT);
  718.                 
  719.                 EraseRect(&qd.thePort->portRect);
  720.             }
  721.             
  722.             CloseResFile(curResRefNum);
  723.             All_Done = TRUE;
  724.         } 
  725.        }
  726.        All_Done = TRUE;
  727. }
  728.  
  729. //************************************************************************
  730. void DoError (char desc[255], short OScode, short myRef, Boolean fatal)
  731. {
  732.     /* A fatal error has occurred - report it and quit */
  733.     short go;
  734.     Str63    a, b;
  735.     
  736.     c2pstr(desc);
  737.     NumToString (OScode, a);
  738.     NumToString (myRef, b);
  739.     ParamText ((StringPtr)desc, a, b, NULL);
  740.     NoteAlert(kErrorAlertID,NULL);
  741.     if(fatal)
  742.         ExitToShell();
  743. }
  744.  
  745. /* This filters out (discards) non-sprite files.*/
  746. pascal Boolean SpriteGuyFileFilter(fileParam *thePB )
  747. {
  748.     if (thePB->ioFlFndrInfo.fdType=='Ned3')
  749.         return(FALSE);        /* SF2K3 file, keep it in the list */
  750.     else if ( thePB->ioFlFndrInfo.fdType == 'Ned2' )
  751.         return(FALSE);        /* SF2K2 file, keep it in the list */
  752.     else
  753.         return(TRUE);            /* Nope, filter it from the list */
  754. }